package com.lzw.okgoutils.http.struct;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class StringMultiFileMap extends HashMap<String, List<FileBody>> {

    public List<String> getKeyList(){
        List<String> keyList = new ArrayList<String>();
        for (Entry<String, List<FileBody>> entry : entrySet()) {
            keyList.add(entry.getKey());
        }
        return keyList;
    }

    public List<List<FileBody>> getFileBodyList(){
        List<List<FileBody>> list = new ArrayList<List<FileBody>>();
        for (Entry<String, List<FileBody>> entry : entrySet()) {
            list.add(entry.getValue());
        }
        return list;
    }

    public List<List<File>> getRawFileList(){
        List<List<File>> list = new ArrayList<List<File>>();
        for (Entry<String, List<FileBody>> entry : entrySet()) {
            List<FileBody> fblist = entry.getValue();
            List<File> flist = new ArrayList<File>();
            for (FileBody fileBody : fblist) {
                flist.add(fileBody.getFile());
            }
            list.add(flist);
        }
        return list;
    }

    @Override
    public String toString() {
        if (isEmpty()) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder();
        for (Entry<String, List<FileBody>> entry : this.entrySet()) {
            sb.append(entry.getKey()).append("=").append("[");

            List<FileBody> list = entry.getValue();
            for (FileBody fileBody : list) {
                sb.append(fileBody.getFile().getPath()).append(",");
            }
            sb.append("]").append(",");
        }
        String res = sb.toString();
        return res.substring(0, res.length()-1);
    }
}
